package org.dingyom.gift.exception.asserts;

import com.sun.javafx.css.StringStore;
import org.dingyom.gift.exception.BusinessException;
import org.dingyom.gift.exception.code.StatusCode;

import java.util.List;

public class Assert {

    /**
     * 断言不为空 为空就抛出异常
     * @param obj
     * @param message
     */
    public static void notNull(Object obj,String message){
        if (obj==null){
            throw new BusinessException(message);
        }
    }

    /**
     * 断言是空
     * @param obj
     * @param code
     */
    public static void isNull(Object obj,StatusCode code){
        if (obj!=null){
            throw new BusinessException(code.getCode(),code.getMessage());
        }
    }

    /**
     * 断言字符串不为空
     * @param str
     * @param message
     */
    public static void isNotEmpty(String str,String message){
        if (str==null||str.equals("")){
            throw new BusinessException(message);
        }
    }
    public static void isNotEmpty(String str,StatusCode code){
        if (str==null||str.equals("")){
            throw new BusinessException(code.getCode(),code.getMessage());
        }
    }

    /**
     * 断言字符串是空
     * @param str
     * @param code
     */
    public static void isEmpty(String str,StatusCode code){
        if (str!=null&&str.equals("")){
            throw new BusinessException(code.getCode(),code.getMessage());
        }
    }

    /**
     * 断言字符串为空
     * @param str
     * @param message
     */
    public static void isEmpty(String str,String message){
        if (str!=null&&str.equals("")){
            throw new BusinessException(message);
        }
    }

    /**
     * 断言 list为空
     * @param list
     * @param message
     */
    public static void listIsNull(List<?> list, String message){
        if (list!=null && list.size()>0){
            throw new BusinessException(message);
        }
    }
    /*错误码版*/
    public static void listIsNull(List<?> list, StatusCode code){
        if (list!=null && list.size()>0){
            throw new BusinessException(code.getCode(),code.getMessage());
        }
    }

    /**
     * 断言 list不为空
     * @param list
     * @param message
     */
    public static void listNotNull(List<?> list, String message){
        if (list==null && list.size()>0){
            throw new BusinessException(message);
        }
    }

    /**
     * 断言list不为空
     * @param list
     * @param code
     */
    public static void assertListNotEmpty(List<?> list, StatusCode code) {
        if (list==null || list.size()<1){
            throw new BusinessException(code.getCode(),code.getMessage());
        }
    }

    /**
     * 断言这是对的
     * @param bl
     * @param code
     */
    public static void isTrue(Boolean bl,StatusCode code){
        if (!bl){
            throw new BusinessException(code.getCode(),code.getMessage());
        }
    }

    /**
     * 断言不区分大小写比较
     * @param smsCode
     * @param sms
     * @param code
     */
    public static void equalsIgnoreCase(String smsCode, String sms, StatusCode code) {
        boolean b = smsCode.equalsIgnoreCase(sms);
        if (!b){
            throw new BusinessException(code.getCode(),code.getMessage());
        }
    }


}
